﻿using BlawkayEngine.ScreenSystem;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Net;
using BlawkayEngine;

namespace BlawkayHockey
{
    public class SearchResultsScreen : XboxLiveSettingsScreen
    {

        public SearchResultsScreen(Game oGame)
            : base(oGame, "Search Results")
        {
            if (Networking.AvailableSessions.Count == 0)
            {
                AddMenuOption("No Results Found");
            }
            else
            {
                foreach (AvailableNetworkSession oAvailableSession in Networking.AvailableSessions)
                {
                    AddMenuOption(oAvailableSession.HostGamertag);
                }
            }
        }

        protected override void Select(ScreenManager oManager)
        {
            if (Networking.IsAvailableMatchesReady == false || Networking.AvailableSessions.Count == 0)
                return;

            GoToMenu(XboxLiveDestination.JoinLobby, oManager);
        }

        protected override void Cancel(ScreenManager oManager)
        {
            GoToMenu(XboxLiveDestination.XboxLive, oManager);
        }

        public override void Draw(ScreenManager oManager, SpriteBatch oSB)
        {
            base.Draw(oManager, oSB);

            if (Networking.AvailableSessions.Count > 0)
            {
                Vector2 oOrigin = Vector2.Zero;
                SpriteEffects oEffect = SpriteEffects.None;
                float oScale = 1.0f;
                float oRotation = 0.0f;

                string oMessage = Networking.InformationAboutCurrentSession();
                Vector2 oMeasure = _FontMenuOption.MeasureString(oMessage);

                Rectangle oBackgroundRect = new Rectangle(550, 100, 400, 1);
                oBackgroundRect.Height = (int)oMeasure.Y + 6;
                oSB.Draw(_BackgroundMenuOption, oBackgroundRect, null, Color.Black * 0.25f, 0.0f, oOrigin, oEffect, 0.5f);

                Vector2 oPosition = new Vector2(oBackgroundRect.Left + 5, oBackgroundRect.Top + 3);
                oSB.DrawString(_FontMenuOption, oMessage, oPosition, Color.White, oRotation, oOrigin, oScale, oEffect, 1.0f);
            }
        }

    }
}